package com.company;

import java.math.BigDecimal;
import java.math.RoundingMode;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.Data;

public class DecimalMain {
    public static void main(String[] args) {
        BigDecimal num1 = new BigDecimal(RandomUtil.randomInt());
        BigDecimal num2 = new BigDecimal(10);

        System.out.println(num1.divide(num2, RoundingMode.CEILING));

        System.out.println(new BigDecimal(RandomUtil.randomInt()).divide(new BigDecimal(100), 2, RoundingMode.CEILING));

        System.out.println(new BigDecimal("22.93495000").stripTrailingZeros().toPlainString());

        DemoC demo = new DemoC();
        demo.setNumber(new BigDecimal("22.93495000"));
        JSONObject sourceJson = JSONUtil.parseObj(demo);
        sourceJson.forEach((k, v) -> {
            if (v instanceof BigDecimal) {
                BigDecimal bigDecimal = ((BigDecimal)v).stripTrailingZeros();
                System.out.println(bigDecimal);
            }
        });
    }

    @Data
    static class DemoC {

        private BigDecimal number;
    }
}
